<?php

/**
 * * create condition functions
 * @author DuongNV
 * @copyright Tan MA JSC
 * @category common function
 * @version 1.1
 */

/**
 *
 * @param unknown_type $id
 * @param unknown_type $array
 */
function createSubIDArray($id, $array, $type = null){

    $db = new DBAccess();
    if ($type == null){
    	$subCategories = $db->selectManyByCause( array(CATEGORY_ID, CATEGORY_URL, CATEGORY_FID, CATEGORY_TITLE), CATEGORIES, array(CATEGORY_FID => $id));
    } else {
    	$subCategories = $db->selectManyByCause( array(CATEGORY_ID, CATEGORY_URL, CATEGORY_FID, CATEGORY_TITLE), CATEGORIES, array(CATEGORY_FID => $id, SQL_AND, CATEGORY_TYPE => $type));
    }
    
    if ($subCategories == null || count($subCategories) == 0){
        return $array;
    } else {
        $n = count($array);
        foreach ($subCategories as $cate) {
            $array[$n] = $cate[CATEGORY_ID];
            $array = createSubIDArray($cate[CATEGORY_ID], $array);
            $n = count($array);
        }
        return $array;
    }
}

/**
 *
 * @param unknown_type $categoryURL
 * @param unknown_type $key
 * @return multitype:unknown string
 */
function createSubConditionByID($id, $column , $language = DEFAULT_LANGAUGE) {

    $conArrayVaule = array();
    $conArrayVaule[0] = $id;
    $conArrayVaule = createSubIDArray($id, $conArrayVaule);

    $conArray = array(array('key' => IN, 'column' => $column, 'value' => $conArrayVaule), SQL_AND, array('key' => LIKE, 'column' => PRODUCT_LANGUAGE, 'value' => $language));
    return $conArray;
}


?>